package cn.petplatform.petback.controller.sysmessage;

import cn.petplatform.annotations.LoginVerifyToken;
import cn.petplatform.annotations.PassToken;
import cn.petplatform.dto.ResponseDto;
import cn.petplatform.petback.pojo.Pet;
import cn.petplatform.petback.pojo.SysMessage;
import cn.petplatform.petback.pojo.vo.SystemMessageVo;
import cn.petplatform.petback.service.sysmessage.SysMessageService;
import cn.petplatform.utils.JWTUtils;
import cn.petplatform.utils.UUIDUtils;
import com.auth0.jwt.interfaces.DecodedJWT;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.Optional;

/**
 * @author LNL
 * @date 2021/5/13 15:23
 */
@RestController
@Api(tags = "系统消息控制器")
///systemMessage/systemMessages，springboot的注解
@RequestMapping("/systemMessage")
@Slf4j
public class SystemMessageController {

    @Autowired
    private SysMessageService sysMessageService;

    /**
     * 查询所有的系统消息
     * @return
     */
    //通过验证
    @PassToken
    //接口信息
    @ApiOperation("获取系统消息")
    //路径接收
    @GetMapping("/systemMessages")
    public ResponseDto getAllSystemMessages() {
        ResponseDto responseDto = sysMessageService.getAllSystemMessages();
        return responseDto;
    }

    @PassToken
    @ApiOperation("通过id获取系统消息")
    @GetMapping("/message/{id}")
    public ResponseDto getSystemMessagesById(@PathVariable("id") @ApiParam("消息id") String id) {
        ResponseDto responseDto = sysMessageService.getSystemMessagesById(id);
        return responseDto;
    }

    /*
    * 增加系统消息，在后台系统处理的时候，当宠物发布上来之后，提供一个按钮，点击按钮发布消息
    * */
    @LoginVerifyToken
    @PostMapping("/insert")
    public ResponseDto insertSystemMessage(@RequestBody SysMessage sysMessage,HttpServletRequest request) {
        ResponseDto responseDto = sysMessageService.insertSystemMessage(sysMessage,request);
        return responseDto;
    }



    /*
    * 修改系统消息
    * */
    @LoginVerifyToken
    @PostMapping("/update")
    public ResponseDto updateSystemMessage(@RequestBody SysMessage sysMessage, HttpServletRequest request) {
        ResponseDto responseDto = sysMessageService.updateSystemMessage(sysMessage,request);
        return responseDto;
    }

    @ApiOperation("删除系统消息")
    @LoginVerifyToken
    @PostMapping("/delete/{id}")
    public ResponseDto deleteSystemMessage(@PathVariable("id") String id) {
        ResponseDto responseDto = sysMessageService.deleteSystemMessage(id);
        return responseDto;
    }

    @ApiOperation("获取未审核的发布宠物")
    @PassToken
    @GetMapping("/notPass")
    public ResponseDto getPublishIsPassAsZero() {
        ResponseDto responseDto = sysMessageService.getPublishIsPassAsZero();
        return responseDto;
    }







}
